<?php

namespace app\common\com\mail;

class EmailFactory {

	/**
	 * 获取一个邮件处理对象
	 */
	public static function getInstance($type = '', array $config = array()) {
		static $return = null;
		if($return instanceof IMail) {
			return $return;
		}
		$site_config = load_site_config();
		$cfg = empty($config) ? $site_config['mail'] : $config;
		$type = empty($type) ? $cfg['type'] : $type;
		require_once (__DIR__ . '/interface/' . $type . '.class.php');
		$class_name = '\\' . $type;
		$mail = new $type($cfg);
		if(!$mail instanceof IMail) {
			exception('mail interface invalid');
		}
		return $mail;
	}
	
}